package com.zs.consumer;

import com.alibaba.dubbo.rpc.RpcContext;
import com.zs.service.HelloService;
import com.zs.service.RadomService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;

/**
 * Created by zhangshuqing on 2017/6/3.
 */
public class ConsumerClient {
    public static void main(String[] args) throws IOException {
        ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("duboo-consumer.xml");
        boolean isConsumer=RpcContext.getContext().isConsumerSide();
        System.out.println(isConsumer);
        HelloService helloService= (HelloService) context.getBean("helloService");
        //可以通过 RpcContext 上的 setAttachment 和 getAttachment 在服务消费方和提供方之间进行参数的隐式传递
        //path, group, version, dubbo, token, timeout 几个 key 是保留字段，请使用其它值
        RpcContext.getContext().setAttachment("index","1");
        String result=helloService.sayHello("zsq");
        System.out.println(result);
        //每次发起Rpc调用上下文状态都会发生变化
        isConsumer=RpcContext.getContext().isConsumerSide();
        System.out.println(isConsumer);
        RadomService r= (RadomService) context.getBean("radomService");
        System.out.println(r.getRadomStr());
        System.in.read();
    }
}
